<?php

namespace app\notify\controller;

use Throwable;
use app\BaseController;
use think\Response;
use think\exception\HttpResponseException;
use think\Exception;
use think\facade\Log;
use app\common\library\MpPay;
use app\api\library\OrderPayment;


/**
 * API控制器基类
 */
class Notify extends BaseController
{
    
    
    /**
     * 控制器初始化方法
     * @access protected
     * @throws Throwable
     */
    protected function initialize(): void
    {
        // 系统站点配置
        set_timezone(); // 时区设定
        parent::initialize();
    }

    public function index(){
        Log::info(json_encode($this->request->param()));
        try {

            $notify =  MpPay::notify();
            if($notify === false){
                throw new Exception('error');
            }
            $notify['out_trade_no'];
            $result = ["code"=> "SUCCESS","message"=> "成功"];
            $code="200";
            $payInfo = OrderPayment::order($notify['out_trade_no']);
        
        } catch (\Throwable $th) {
            $result = ["code"=> "FAIL","message"=> "失败"];
            $code="400";
            
        }
        $response = Response::create($result, 'json', $code);
        throw new HttpResponseException($response);

    }

}